package com.estacionamientos.security

import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;

import cr.co.arquetipos.crypto.Blowfish;

public class EstacionamientosEncoder implements PasswordEncoder {

	String privateKey
	
	public EstacionamientosEncoder() {
		super();
	}

	@Override
	public String encodePassword(String password, Object key)
			throws DataAccessException {
		return Blowfish.encryptBase64(password,privateKey);
	}
	
	public String encodePassword(String password)throws DataAccessException {
		return Blowfish.encryptBase64(password,privateKey);
	}

	@Override
	public boolean isPasswordValid(String encryptedPass, String rawPass, Object key)
			throws DataAccessException {
		if(encryptedPass == null || rawPass == null)
			return false;
		return rawPass.equals(Blowfish.decryptBase64( encryptedPass, privateKey, true));
	}
			
	public String decodePassword(String encryptedPass){
		return Blowfish.decryptBase64( encryptedPass, privateKey, true);	
	}
			
	

}
